<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JVM内存模型深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
        }
        
        .memory-card {
            background: white;
            border-radius: 16px;
            padding: 24px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            border: 1px solid rgba(102, 126, 234, 0.1);
        }
        
        .memory-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(102, 126, 234, 0.2);
            border-color: rgba(102, 126, 234, 0.3);
        }
        
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            padding: 20px;
            border-radius: 8px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .info-badge {
            display: inline-flex;
            align-items: center;
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.875rem;
            margin: 0 4px;
        }
        
        table {
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
        }
        
        th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: 600;
            padding: 16px;
            text-align: left;
        }
        
        td {
            padding: 16px;
            border-bottom: 1px solid #e2e8f0;
        }
        
        tr:last-child td {
            border-bottom: none;
        }
        
        tr:hover {
            background: rgba(102, 126, 234, 0.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    JVM内存模型
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深入理解Java虚拟机的核心机制
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="info-badge bg-white bg-opacity-20 text-white">
                        <i class="fas fa-microchip mr-2"></i>内存管理
                    </span>
                    <span class="info-badge bg-white bg-opacity-20 text-white">
                        <i class="fas fa-sync-alt mr-2"></i>垃圾回收
                    </span>
                    <span class="info-badge bg-white bg-opacity-20 text-white">
                        <i class="fas fa-layer-group mr-2"></i>多线程
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <div class="content-card rounded-2xl shadow-xl p-8 md:p-12">
                    <p class="text-lg leading-relaxed text-gray-700 mb-6">
                        <span class="drop-cap">J</span>VM内存模型这一关键知识点，不仅是理解Java程序运行机制的基础，也是深入优化Java应用性能的核心。无论你是开发业务系统、构建分布式架构，还是进行高性能计算，了解JVM内存模型都能帮助你更好地解决问题。
                    </p>
                    <p class="text-lg leading-relaxed text-gray-700">
                        JVM内存模型（Java Memory Model, JMM）定义了线程之间如何共享变量以及如何保证线程安全。它不仅决定了Java程序中对象的分配和回收，还深刻影响了多线程环境下的代码行为。为什么有些代码在本地测试一切正常，放到生产环境却会出问题？为什么有时明明已经设置了多线程同步，结果却不符合预期？这些问题往往都与JVM内存模型相关。
                    </p>
                </div>
            </div>
        </div>
    </section>

    <!-- Memory Model Overview -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-4xl font-bold mb-12 text-center gradient-text">JVM内存模型概述</h2>
                
                <div class="grid md:grid-cols-3 gap-6 mb-12">
                    <div class="memory-card">
                        <div class="text-3xl mb-4 text-purple-600">
                            <i class="fas fa-shield-alt"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">线程安全性</h3>
                        <p class="text-gray-600">确保多线程程序中的数据一致性，避免因并发修改共享变量导致的错误。</p>
                    </div>
                    <div class="memory-card">
                        <div class="text-3xl mb-4 text-purple-600">
                            <i class="fas fa-globe"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">跨平台性</h3>
                        <p class="text-gray-600">屏蔽底层硬件和操作系统的差异，让Java程序在不同平台上表现一致。</p>
                    </div>
                    <div class="memory-card">
                        <div class="text-3xl mb-4 text-purple-600">
                            <i class="fas fa-rocket"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">高效性</h3>
                        <p class="text-gray-600">通过一定程度的优化和重排序，提升程序的运行效率，同时维持正确性。</p>
                    </div>
                </div>

                <!-- Memory Structure Diagram -->
                <div class="content-card rounded-2xl shadow-xl p-8">
                    <h3 class="text-2xl font-bold mb-6 section-title">JVM内存结构图</h3>
                    <div class="mermaid">
                        graph TB
                            subgraph "JVM内存模型"
                                subgraph "线程私有"
                                    PC[程序计数器]
                                    VS[虚拟机栈]
                                    NS[本地方法栈]
                                end
                                subgraph "线程共享"
                                    subgraph "堆内存"
                                        YG[新生代]
                                        OG[老年代]
                                    end
                                    MA[方法区/元空间]
                                end
                                DM[直接内存]
                            end
                            
                            YG --> |晋升| OG
                            VS --> |引用| YG
                            VS --> |引用| OG
                            
                            style PC fill:#e1bee7,stroke:#8e24aa
                            style VS fill:#e1bee7,stroke:#8e24aa
                            style NS fill:#e1bee7,stroke:#8e24aa
                            style YG fill:#c5cae9,stroke:#3f51b5
                            style OG fill:#c5cae9,stroke:#3f51b5
                            style MA fill:#c5cae9,stroke:#3f51b5
                            style DM fill:#b2dfdb,stroke:#00796b
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Memory Areas Detail -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-4xl font-bold mb-12 text-center gradient-text">JVM内存区域详解</h2>
                
                <!-- Thread Private Areas -->
                <div class="mb-16">
                    <h3 class="text-3xl font-bold mb-8 section-title">线程私有区域</h3>
                    
                    <div class="space-y-6">
                        <div class="content-card rounded-xl shadow-lg p-6">
                            <h4 class="text-xl font-bold mb-3 flex items-center">
                                <i class="fas fa-microchip mr-3 text-purple-600"></i>
                                程序计数器
                            </h4>
                            <p class="text-gray-700 mb-3">每个线程都有自己的程序计数器，用来记录当前线程正在执行的字节码指令地址。</p>
                            <div class="bg-purple-50 rounded-lg p-4">
                                <p class="text-sm text-purple-800">
                                    <i class="fas fa-info-circle mr-2"></i>
                                    特点：线程私有，不会发生内存溢出（OutOfMemoryError）
                                </p>
                            </div>
                        </div>
                        
                        <div class="content-card rounded-xl shadow-lg p-6">
                            <h4 class="text-xl font-bold mb-3 flex items-center">
                                <i class="fas fa-layer-group mr-3 text-purple-600"></i>
                                Java虚拟机栈
                            </h4>
                            <p class="text-gray-700 mb-3">保存每个线程的方法调用信息，包括局部变量、操作数栈、动态链接和方法出口等。</p>
                            <div class="grid md:grid-cols-2 gap-4 mt-4">
                                <div class="bg-blue-50 rounded-lg p-4">
                                    <h5 class="font-semibold text-blue-800 mb-2">栈帧组成</h5>
                                    <ul class="text-sm text-blue-700 space-y-1">
                                        <li><i class="fas fa-check mr-2"></i>局部变量表</li>
                                        <li><i class="fas fa-check mr-2"></i>操作数栈</li>
                                        <li><i class="fas fa-check mr-2"></i>动态链接</li>
                                        <li><i class="fas fa-check mr-2"></i>方法返回地址</li>
                                    </ul>
                                </div>
                                <div class="bg-red-50 rounded-lg p-4">
                                    <h5 class="font-semibold text-red-800 mb-2">可能的异常</h5>
                                    <ul class="text-sm text-red-700 space-y-1">
                                        